package com.ss.android.a;

import android.content.SharedPreferences;

import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.collection.c;
import com.ss.android.common.AppContext;
import com.ss.android.common.util.ToolUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;

public final class AbManager {
    public final Map a;
    public c b;
    public boolean c;
    public String d;
    public String abVersion;
    private static AbManager f;
    private final List g;
    private AppContext h;
    private String i;
    private int j;
    private static int k;

    private AbManager(AppContext arg8) {
        JSONObject v0_2;
        int v5 = -1;
        this.a = new HashMap();
        this.g = new ArrayList();
        this.b = new c();
        this.j = v5;
        this.h = arg8;
        if(!ToolUtils.isMainProcess(this.h.getContext())) {
            if(Logger.debug()) {
                Logger.d("AbManager", "Don\'t support non-main-process init.");
            }
            this.c = false;
            return;
        }

        SharedPreferences v0 = this.getAppSettingsSp();
        if(v0 != null) {
            this.abVersion = v0.getString("ab_version", "");
            this.j = v0.getInt("ab_first_install_version", v5);
            int v1 = k;
            int v2 = this.h.getVersionCode();
            if(v1 <= 0) {
                v0.edit().putInt("ab_first_install_version", v2).apply();
                this.j = v2;
            }

            if(Logger.debug()) {
                Logger.d("AbManager", "first install version: " + this.j);
            }

            if(v2 == v1) {
                if(Logger.debug()) {
                    Logger.d("AbManager", "init from local.");
                }

                this.f();
                JSONObject v1_1 = null;
                try {
                    v0_2 = new JSONObject(this.getAppSettingsSp().getString("ab_client_keys", ""));
                }
                catch(Throwable v0_1) {
                    v0_1.printStackTrace();
                    v0_2 = v1_1;
                }

                this.a(v0_2);
                if(!Logger.debug()) {
                }else {
                    Logger.d("AbManager", "mAbLayer = " + this.g);
                    Logger.d("AbManager", "mAbClientKeys = " + this.a);
                }
            }else {
                if (Logger.debug()) {
                    Logger.d("AbManager", "upgrade from " + v1 + " to " + v2);
                }

                v0 = this.getAppSettingsSp();
                v1 = v0.getInt("ab_migration_version", v5);
                if (v1 <= 0) {
                    if (Logger.debug()) {
                        Logger.d("AbManager", "migrate, lastMigrationVersion = " + v1 + ", currentMigrationVersion = 1");
                    }

                    SharedPreferences.Editor v0_3 = v0.edit();
                    v0_3.putInt("ab_migration_version", 1);
                    v0_3.apply();
                } else if (Logger.debug()) {
                    Logger.d("AbManager", "Don\'t need migrate. currentMigrationVersion = 1");
                }

                this.d();
            }
        label_87:
            this.c = true;
            if(Logger.debug()) {
                Logger.d("AbManager", "AbGroup: " + this.a());
                Logger.d("AbManager", "AbClient: " + this.b());
            }
        }
    }

    public static AbManager getInstance(AppContext arg2) {
        if(f == null) {
            Class v1 = AbManager.class;
            synchronized (v1){
                if(f == null) {
                    f = new AbManager(arg2);
                }
            }
        }

        return f;
    }

    private void a(JSONObject arg13) {
        JSONObject v6;
        Object v0;
        this.a.clear();
        if(arg13 != null && arg13.length() > 0) {
            SharedPreferences v3 = this.getAppSettingsSp();
            SharedPreferences.Editor v4 = v3.edit();
            Iterator v5 = arg13.keys();
            int v1 = 0;
            do {
            label_11:
                if(v5.hasNext()) {
                    v0 = v5.next();
                    if(android.support.design.a.isTextEmpty(((String)v0))) {
                        continue;
                    }

                    v6 = arg13.optJSONObject(((String)v0));
                    if(v6 == null) {
                        continue;
                    }

                    Iterator v7 = v6.keys();
                    HashMap v8 = new HashMap();
                    int v2 = v1;
                    while(v7.hasNext()) {
                        Object v1_1 = v7.next();
                        String v9 = v6.optString(((String)v1_1));
                        if(android.support.design.a.isTextEmpty(((String)v1_1))) {
                            continue;
                        }

                        if(android.support.design.a.isTextEmpty(v9)) {
                            continue;
                        }

                        if("__default_key".equals(v1_1)) {
                            if(v3.contains(((String)v0))) {
                                continue;
                            }

                            v4.putString(((String)v0), v9);
                            v2 = 1;
                            if(!Logger.debug()) {
                                continue;
                            }

                            Logger.d("AbManager", "set defalut value: " + (((String)v0)) + " = " + v9);
                        } else {
                            ((Map)v8).put(v1_1, v9);
                        }
                    }

                    if(!((Map)v8).isEmpty()) {
                        this.a.put(v0, v8);
                        v1 = v2;
                    } else {
                        v1 = v2;
                    }
                    continue;
                } else {
                   break;
                }
            }
            while(true);
            if(v1 != 0) {
                v4.apply();
            }
        }
    }

    public final String a() {
        if((this.c) && this.i == null) {
            StringBuilder v2 = new StringBuilder();
            Iterator v3 = this.g.iterator();
            int v1;
            for(v1 = 1; v3.hasNext(); v1 = v1) {
                Object v0 = v3.next();
                if(v0 == null) {
                    continue;
                }

                if(android.support.design.a.isTextEmpty(((ABLayer)v0).experiment)) {
                    continue;
                }

                if("__default_key".equals(((ABLayer)v0).experiment)) {
                    continue;
                }

                if("__no_experiment".equals(((ABLayer)v0).experiment)) {
                    continue;
                }

                if(((ABLayer)v0).endTimeStamp <= 0 || ((ABLayer)v0).endTimeStamp >= System.currentTimeMillis()) {
                    if(v1 != 0) {
                        v1 = 0;
                    }
                    else {
                        v2.append(",");
                    }

                    v2.append(((ABLayer)v0).experiment);
                }
            }

            this.i = v2.toString();
        }

        return this.i;
    }

    private static int a(String arg1, int arg2) {
        if(arg1 != null) {
            try {
                if(arg1.length() == 0) {
                    return arg2;
                }

                arg2 = Integer.parseInt(arg1);
            }
            catch(Exception v0) {
            }
        }

        return arg2;
    }

    private ABLayer a(String arg5) {
        ABLayer v0_1;
        Iterator v1 = this.g.iterator();
        do {
            if(v1.hasNext()) {
                Object v0 = v1.next();
                if(v0 == null) {
                    continue;
                }

                if(!"lite_feed_ui_layer".equals(((ABLayer)v0).name) && !"lite_feed_ui_old_user_layer".equals(((ABLayer)v0).name)) {
                    continue;
                }

                if(!arg5.equals(((ABLayer)v0).experiment)) {
                    continue;
                }
                return (ABLayer) v0;
            } else {
                break;
            }
        }
        while(true);

        v0_1 = null;
        return v0_1;
    }

    private String a(int arg14, JSONArray arg15) {
        String v0 = null;
        int v1_1 = 0;
        Iterator v4_1;
        JSONObject v3_1;
        String v2;
        int v11 = -1;
        String v1 = "__no_experiment";
        if(arg15 == null || arg15.length() <= 0) {
            v0 = "__no_experiment";
        }
        else {
            int v4 = arg15.length();
            SharedPreferences v5 = this.getAppSettingsSp();
            SharedPreferences.Editor v6 = v5.edit();
            int v3;
            boolean bingo = false;
            for(v3 = 0; v3 < v4; ++v3) {
                JSONObject v7 = arg15.optJSONObject(v3);
                if(v7 != null) {
                    v2 = v7.optString("group_name");
                    int v8 = v7.optInt("min_region", v11);
                    int v9 = v7.optInt("max_region", v11);
                    if(!android.support.design.a.isTextEmpty(v2) && v8 >= 0 && v9 >= 0 && v8 <= v9 && arg14 >= v8 && arg14 <= v9) {
                        v3_1 = v7.optJSONObject("results");
                        if(v3_1 != null && v3_1.length() > 0) {
                            v4_1 = v3_1.keys();
                            if(Logger.debug()) {
                                Logger.d("AbManager", "hit experiment: " + v2);
                            }
                            v1_1 = 0;
                            while(v4_1.hasNext()) {
                                Object v0_1 = v4_1.next();
                                String v7_1 = v3_1.optString(((String)v0_1));
                                if(android.support.design.a.isTextEmpty(((String)v0_1))) {
                                    continue;
                                }

                                if(android.support.design.a.isTextEmpty(v7_1)) {
                                    continue;
                                }

                                if(v5.getAll().get(v0_1) != null) {
                                    continue;
                                }

                                v6.putString(((String)v0_1), v7_1);
                                v1_1 = 1;
                                if(!Logger.debug()) {
                                    continue;
                                }

                                Logger.d("AbManager", "save experiment result: " + (((String)v0_1)) + " = " + v7_1);
                            }

                            v0 = v2;
                        }else {
                            v1_1 = 0;
                            v0 = v2;
                        }
                        bingo = true;
                        break;
                    }
                }
            }
            if(bingo){

            }else{
                v0 = v1;
                v1_1 = 0;
            }
            if(v1_1 == 0) {
                return v0;
            }
            v6.apply();
        }
        return v0;
    }

    public static void a(int arg0) {
        k = arg0;
    }

    private void a(JSONArray arg13) {
        Object v0;
        int v11 = 1000;
        this.f();
        ArrayList v7 = new ArrayList(this.g);
        this.g.clear();
        if(arg13 != null && arg13.length() > 0) {
            int v8 = arg13.length();
            Random v9 = new Random();
            int v6;
            for(v6 = 0; v6 < v8; ++v6) {
                JSONObject v2 = arg13.optJSONObject(v6);
                if(v2 != null) {
                    String v1 = v2.optString("layer_name");
                    if(!android.support.design.a.isTextEmpty(v1)) {
                        int v3 = -1;
                        Iterator v4 = ((List)v7).iterator();
                        do {
                            if(v4.hasNext()) {
                                v0 = v4.next();
                                if(v0 == null) {
                                    continue;
                                }

                                if(!v1.equals(((ABLayer)v0).name)) {
                                    continue;
                                }

                                v3 = ((ABLayer)v0).randomNum;
                                v4.remove();
                                if(Logger.debug()) {
                                    Logger.d("AbManager", "layerName = " + v1 + ", last randomNum = " + v3);
                                }
                            }

                          break;
                        } while(true);
                        if(v3 < 0 || v3 >= v11) {
                            v3 = v9.nextInt(v11);
                        }

                        long v4_1 = b(v2.optJSONObject("filters"));
                        String v0_1 = null;
                        if((this.c(v2.optJSONObject("filters"))) && !this.d(v1)) {
                            v0_1 = this.a(v3, v2.optJSONArray("experiments"));
                        }

                        String v2_1 = android.support.design.a.isTextEmpty(v0_1) ? "__no_experiment" : v0_1;
                        this.g.add(new ABLayer(v1, v2_1, v3, v4_1));
                    }
                }
            }
        }
    }

    public final String b() {
        int v1_2 = 0;
        long v10 = 0;
        if((this.c) && this.d == null) {
            StringBuilder v3 = new StringBuilder();
            SharedPreferences v4 = this.getAppSettingsSp();
            Iterator v5 = this.a.entrySet().iterator();
            int v2;
            for(v2 = 1; v5.hasNext(); v2 = v1_2) {
                Entry<String,Map> v0 = (Entry<String, Map>) v5.next();
                if(android.support.design.a.isTextEmpty(v0.getKey())) {
                    continue;
                }

                String v1 = v4.getString(v0.getKey(), "");
                if(android.support.design.a.isTextEmpty(v1)) {
                    continue;
                }

                Map value = v0.getValue();
                if(value == null) {
                    continue;
                }

                if(value.isEmpty()) {
                    continue;
                }

                String value2 = (String) value.get(v1);
                if(android.support.design.a.isTextEmpty(value2)) {
                    continue;
                }

                ABLayer v1_1 = this.a(value2);
                if(v1_1 != null && v1_1.endTimeStamp > v10 && v1_1.endTimeStamp < System.currentTimeMillis()) {
                    continue;
                }

                v1_1 = this.b(((String)value2));
                if(v1_1 != null && v1_1.endTimeStamp > v10 && v1_1.endTimeStamp < System.currentTimeMillis()) {
                    continue;
                }

                v1_1 = this.c(((String)value2));
                if(v1_1 != null && v1_1.endTimeStamp > v10 && v1_1.endTimeStamp < System.currentTimeMillis()) {
                    continue;
                }

                if(v2 != 0) {
                    v1_2 = 0;
                } else {
                    v3.append(",");
                    v1_2 = v2;
                }

                v3.append(((String)value2));
            }

            this.d = v3.toString();
        }

        return this.d;
    }

    private static long b(JSONObject arg6) {
        String v4;
        long v2 = -1;
        if(arg6 != null) {
            Iterator v1 = arg6.keys();
            do {
                if(v1.hasNext()) {
                    Object v0 = v1.next();
                    v4 = arg6.optString(((String)v0));
                    if(android.support.design.a.isTextEmpty(((String)v0))) {
                        continue;
                    }

                    if(android.support.design.a.isTextEmpty(v4)) {
                        continue;
                    }

                    if(!"end_timestamp".equals(v0)) {
                        continue;
                    }

                    break;
                } else {
                    return v2;
                }
            }
            while(true);
            long v0_1 = Long.valueOf(v4).longValue();
            return v0_1;
        }

        return v2;
    }

    private ABLayer b(String arg5) {
        Object v0;
        Iterator v1 = this.g.iterator();
        do {
            if(v1.hasNext()) {
                v0 = v1.next();
                if(v0 == null) {
                    continue;
                }

                if(!"lite_feed_ui_layer_v2".equals(((ABLayer)v0).name) && !"lite_feed_ui_old_user_layer_v2".equals(((ABLayer)v0).name)) {
                    continue;
                }

                if(!arg5.equals(((ABLayer)v0).experiment)) {
                    continue;
                }
            }
            else {
                v0 = null;
            }

          break;
        }
        while(true);


    label_17:
        return ((ABLayer)v0);
    }

    public final SharedPreferences getAppSettingsSp() {
        return this.h.getContext().getSharedPreferences("app_setting", 0);
    }

    private boolean c(JSONObject arg11) {
        String[] v2_1;
        String v0_3;
        boolean v1_1;
        int v0_2;
        String v2;
        Object v0_1;
        boolean v0 = false;
        if(arg11 == null) {
            v0 = true;
        } else {
            Iterator v4 = arg11.keys();
            SharedPreferences v5 = this.getAppSettingsSp();
            do {
            label_6:
                if(v4.hasNext()) {
                    v0_1 = v4.next();
                    v2 = arg11.optString(((String)v0_1));
                    if(android.support.design.a.isTextEmpty(((String)v0_1))) {
                        continue;
                    }

                    if(android.support.design.a.isTextEmpty(v2)) {
                        continue;
                    }

                    if("first_install_version".equals(v0_1)) {
                        int v1 = -2147483648;
                        v0_2 = 2147483647;
                        if(v2.startsWith(">=")) {
                            v1 = a(v2.substring(2).replaceAll("\\.", ""), -2147483648);
                        }
                        else if(v2.startsWith("<=")) {
                            v0_2 = a(v2.substring(2).replaceAll("\\.", ""), 2147483647);
                        }
                        else if(v2.startsWith(">")) {
                            v1 = a(v2.substring(1).replaceAll("\\.", ""), -2147483648) + 1;
                        }
                        else {
                            if(!v2.startsWith("<")) {
                                continue;
                            }

                            v0_2 = a(v2.substring(1).replaceAll("\\.", ""), 2147483647) - 1;
                        }

                        if(v1 <= this.j && this.j <= v0_2) {
                            v0 = true;
                        }else {
                            v0 = false;
                        }
                    } else {
                        if(!"channel".equals(v0_1)) {
                            if("end_timestamp".equals(v0_1)) {
                                long v0_4 = Long.valueOf(v2).longValue();
                                if(v0_4 > 0 && v0_4 < System.currentTimeMillis()) {
                                    v0 = false;
                                }else {
                                    v0 = true;
                                }
                            }else {
                                v0 = v2.equals(v5.getString(((String) v0_1), ""));
                            }
                        }else {
                            String v6 = this.h.getChannel();
                            if (android.support.design.a.isTextEmpty(v6)) {
                                continue;
                            }

                            v1_1 = v2.startsWith("!");
                            if (v1_1) {
                                if (v2.length() <= 1) {
                                    continue;
                                }

                                v0_3 = v2.substring(1);
                            } else {
                                v0_3 = v2;
                            }

                            v2_1 = v0_3.split(",");
                            if (v2_1 == null) {
                                continue;
                            }

                            if (v2_1.length <= 0) {
                                continue;
                            }
                            int v7 = v2_1.length;
                            v0_2 = 0;
                            boolean bingo = false;
                            while (v0_2 < v7) {
                                String v8 = v2_1[v0_2];
                                if (!android.support.design.a.isTextEmpty(v8) && (v6.equals(v8.trim()))) {
                                    v0 = !v1_1;
                                    bingo = true;
                                } else {
                                    ++v0_2;
                                }
                            }
                            if (bingo) {

                            } else {
                                v0 = v1_1;
                            }
                        }
                    }

                    if(v0) {
                        continue ;
                    }
                    return false;
                } else {
                    return true;
                }
            } while(true);
        }
        return v0;
    }

    private ABLayer c(String arg5) {
        ABLayer v0_1 = null;
        Iterator v1 = this.g.iterator();
        do {
            if(v1.hasNext()) {
                Object v0 = v1.next();
                if(v0 == null) {
                    continue;
                }

                if(!"lite_reduce_launch_time_layer".equals(((ABLayer)v0).name)) {
                    continue;
                }

                if(!arg5.equals(((ABLayer)v0).experiment)) {
                    continue;
                }
            }
            else {
                break;
            }
            return v0_1;
        }
        while(true);

        v0_1 = null;
        return v0_1;
    }

    private void d() {
        BufferedReader v2_1;
        String v0_2;
        BufferedReader v1 = null;
        InputStream v3;
        InputStream v2 = null;
        if(Logger.debug()) {
            Logger.d("AbManager", "init from file.");
        }

        StringBuilder v4 = new StringBuilder();
        try {
            v3 = this.h.getContext().getAssets().open("ab.json");
            if(v3 != null) {
                v1 = new BufferedReader(new InputStreamReader(v3));
                while(true) {
                    v0_2 = v1.readLine();
                    if(v0_2 == null) {
                        break;
                    }
                    v4.append(v0_2);
                }
                v0_2 = v4.toString();
                if(!android.support.design.a.isTextEmpty(v0_2)) {
                    try {
                        JSONObject v1_2 = new JSONObject(v0_2);
                        this.a(v1_2.optJSONObject("filter_keys"));
                        this.a(v1_2.optJSONArray("traffic_map"));
                        this.e();
                        this.g();
                    }
                    catch(Throwable v0) {
                        v0.printStackTrace();
                    }
                }

                if(Logger.debug()) {
                    Logger.d("AbManager", "mAbLayers = " + this.g);
                    Logger.d("AbManager", "mAbClientKeys = " + this.a);
                }
                return;
            }
            return;
        } catch(Throwable v0) {
            v0.printStackTrace();
        }finally {
            if(v1 != null){
                try {
                    v1.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }


    }

    private boolean d(String arg7) {
        JSONObject v2_1;
        String v3 = null;
        boolean v0 = false;
        if(("lite_feed_ui_layer_v2".equals(arg7)) || !"lite_feed_ui_old_user_layer_v2".equals(arg7)) {
            if(!"home_ui_main".equals(this.getAppSettingsSp().getString("homepage_ui_type_old_user", v3)) && !"home_ui_main_with_dot".equals(this.getAppSettingsSp().getString("homepage_ui_type_old_user", v3))) {
                String v4 = this.getAppSettingsSp().getString("ab_experiment_history", "");
                if(!android.support.design.a.isTextEmpty(v4)) {
                    try {
                        v2_1 = new JSONObject(v4);
                    } catch(Exception v2) {
                        v2.printStackTrace();
                        v2_1 = ((JSONObject)null);
                    }
                }else{
                    v2_1 = ((JSONObject)null);
                }
                if(v2_1 != null) {
                    if((v2_1.optString("lite_feed_ui_layer", "").equals("home_ui_main")) || (v2_1.optString("lite_feed_ui_layer", "").equals("home_ui_main_with_dot")) || (v2_1.optString("lite_feed_ui_old_user_layer", "").equals("home_ui_main")) || (v2_1.optString("lite_feed_ui_old_user_layer", "").equals("home_ui_main_with_dot"))) {
                        v0 = true;
                    }

                    if(!v0) {
                        return v0;
                    }

                    Logger.d("AbManager", "Prevent this user enter new ui experiment.");
                } else {
                }

                return v0;
            }

            Logger.d("AbManager", "Prevent this user enter new ui experiment.");
            v0 = true;
        }

        return v0;
    }

    private void e() {
        Object v1;
        Object v0;
        JSONObject v4 = new JSONObject();
        if(!this.a.isEmpty()) {
            Iterator v5 = this.a.entrySet().iterator();
            do {
                if(v5.hasNext()) {
                    v0 = v5.next();
                    v1 = ((Map.Entry)v0).getValue();
                    if(v1 == null) {
                        continue;
                    }

                    if(((Map)v1).isEmpty()) {
                        continue;
                    }

                    Set v2 = ((Map)v1).keySet();
                    JSONObject v6 = new JSONObject();
                    Iterator v7 = v2.iterator();
                    while(v7.hasNext()) {
                        Object v2_1 = v7.next();
                        Object v3 = ((Map)v1).get(v2_1);
                        if(android.support.design.a.isTextEmpty(((String)v2_1))) {
                            continue;
                        }

                        if(android.support.design.a.isTextEmpty(((String)v3))) {
                            continue;
                        }

                        android.support.design.a.a(v6, ((String)v2_1), v3);
                    }

                    android.support.design.a.a(v4, (String) ((Entry)v0).getKey(), v6);
                    continue ;
                }

                break;
            }
            while(true);
        }

        this.getAppSettingsSp().edit().putString("ab_client_keys", v4.toString()).apply();
    }

    private void f() {
        ABLayer v0_3;
        JSONArray v8;
        JSONArray v0_1;
        JSONArray v6 = null;
        this.g.clear();
        String v1 = this.getAppSettingsSp().getString("ab_traffic_map", "");
        try {
            if(!android.support.design.a.isTextEmpty(v1)) {
                v0_1 = new JSONArray(v1);
            } else {
                v0_1 = v6;
            }
            v8 = v0_1;
        }
        catch(Throwable v0) {
            v0.printStackTrace();
            v8 = v6;
        }

        if(v8 != null && v8.length() > 0) {
            int v9 = v8.length();
            int v7;
            for(v7 = 0; v7 < v9; ++v7) {
                JSONObject v0_2 = v8.optJSONObject(v7);
                if(v0_2 != null) {
                    if(v0_2 == null) {
                        v0_3 = ((ABLayer)null);
                    } else {
                        v1 = v0_2.optString("name");
                        String v2 = v0_2.optString("experiment");
                        int v3 = v0_2.optInt("randomNum", -1);
                        long v4 = v0_2.optLong("endTimeStamp", -1);
                        if(!android.support.design.a.isTextEmpty(v1) && !android.support.design.a.isTextEmpty(v2) && v3 >= 0) {
                            v0_3 = new ABLayer(v1, v2, v3, v4);
                        }else {
                            v0_3 = ((ABLayer) null);
                        }
                    }

                    if(v0_3 == null) {
                    }else {
                        this.g.add(v0_3);
                    }
                }
            }
        }
    }

    private void g() {
        JSONObject v0_2;
        SharedPreferences v0 = this.getAppSettingsSp();
        SharedPreferences.Editor v2 = v0.edit();
        JSONObject v1 = null;
        String v3 = v0.getString("ab_experiment_history", "");
        if(!android.support.design.a.isTextEmpty(v3)) {
            try {
                v0_2 = new JSONObject(v3);
            } catch(Exception v0_1) {
                v0_1.printStackTrace();
                v0_2 = v1;
            }
        }else {
            v0_2 = v1;
        }
        v1 = v0_2 == null ? new JSONObject() : v0_2;
        JSONArray v3_1 = new JSONArray();
        if(!this.g.isEmpty()) {
            Iterator v4 = this.g.iterator();
            while(true) {
                if(v4.hasNext()) {
                    Object v0_3 = v4.next();
                    JSONObject v5 = ((ABLayer)v0_3).a();
                    if(v5.length() > 0) {
                        v3_1.put(v5);
                        if("__no_experiment".equals(((ABLayer)v0_3).experiment)) {
                            continue;
                        }

                        android.support.design.a.a(v1, ((ABLayer)v0_3).name, ((ABLayer)v0_3).experiment);
                        continue;
                    }
                } else {
                    v2.putString("ab_traffic_map", v3_1.toString());
                    v2.putString("ab_experiment_history", v1.toString());
                    v2.apply();
                    return;
                }

                return;
            }
        } else {
            v2.putString("ab_traffic_map", v3_1.toString());
            v2.putString("ab_experiment_history", v1.toString());
            v2.apply();
        }
    }
}

